using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region ActionLog

	/// <summary>
	/// ActionLog object for NHibernate mapped table 'ActionLog'.
	/// </summary>
	[Serializable]
	public class ActionLog : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected string _sysNote;
		protected string _comment;
		protected string _actor;
		protected Nullables.NullableDateTime _actionDate;
		protected Step _sourceStep;
		protected Step _targetStep;
		protected Application _application;
		protected Action _action;
		protected Employee _myBackup;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public ActionLog() { }

		public ActionLog( string sysNote, string comment, string actor, Nullables.NullableDateTime actionDate, Step sourceStep, Step targetStep, Application application, Action action, Employee myBackup )
		{
			this._sysNote = sysNote;
			this._comment = comment;
			this._actor = actor;
			this._actionDate = actionDate;
			this._sourceStep = sourceStep;
			this._targetStep = targetStep;
			this._application = application;
			this._action = action;
			this._myBackup = myBackup;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public string SysNote
		{
			get { return _sysNote; }
			set
			{
				if ( value != null && value.Length > 255)
					throw new ArgumentOutOfRangeException("Invalid value for SysNote", value, value.ToString());
				_sysNote = value;
			}
		}

		public string Comment
		{
			get { return _comment; }
			set
			{
				if ( value != null && value.Length > 255)
					throw new ArgumentOutOfRangeException("Invalid value for Comment", value, value.ToString());
				_comment = value;
			}
		}

		public string Actor
		{
			get { return _actor; }
			set
			{
				if ( value != null && value.Length > 100)
					throw new ArgumentOutOfRangeException("Invalid value for Actor", value, value.ToString());
				_actor = value;
			}
		}

		public Nullables.NullableDateTime ActionDate
		{
			get { return _actionDate; }
			set { _actionDate = value; }
		}

		public Step SourceStep
		{
			get { return _sourceStep; }
			set { _sourceStep = value; }
		}

		public Step TargetStep
		{
			get { return _targetStep; }
			set { _targetStep = value; }
		}

		public Application Application
		{
			get { return _application; }
			set { _application = value; }
		}

		public Action Action
		{
			get { return _action; }
			set { _action = value; }
		}

		public Employee MyBackup
		{
			get { return _myBackup; }
			set { _myBackup = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is ActionLog))
				throw new InvalidCastException("This object is not of type ActionLog");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((ActionLog)obj).Id);
					break;
				case "SysNote":
						relativeValue = ( this.SysNote != null ) ? this.SysNote.CompareTo(((ActionLog)obj).SysNote) : -1;
					break;
				case "Comment":
						relativeValue = ( this.Comment != null ) ? this.Comment.CompareTo(((ActionLog)obj).Comment) : -1;
					break;
				case "Actor":
					relativeValue = this.Actor.CompareTo(((ActionLog)obj).Actor);
					break;
				case "ActionDate":
						relativeValue = ( this.ActionDate != null ) ? this.ActionDate.CompareTo(((ActionLog)obj).ActionDate) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (ActionLog.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
